package com.wei.btsearch.components;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import com.wei.btsearch.R;

/**
 * Created by wei on 2017/9/17.
 */
public class FABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {

    public FABBehavior() {
    }

    public FABBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
        if (dependency.getId() == R.id.list) {
            return true;
        } else {
            return super.layoutDependsOn(parent, child, dependency);
        }
    }

    @Override
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
        return true;
    }

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
        if (dyConsumed > 0) {
            child.setVisibility(View.INVISIBLE);
        } else if (dyConsumed < 0) {
            child.setVisibility(View.VISIBLE);
        }
    }
}
